package io.geekidea.springbootplus.system.controller;

import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.system.entity.SysSubscribe;
import io.geekidea.springbootplus.system.entity.SysUser;
import io.geekidea.springbootplus.system.param.SysSubscribePageParam;
import io.geekidea.springbootplus.system.service.SysSubscribeService;
import io.geekidea.springbootplus.system.vo.SysSubscribeQueryVo;
import io.geekidea.springbootplus.system.vo.SysUserQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/sysSubscribe")
@Module("system")
@Api(value = "预约表管理API接口",tags = {"预约表管理"})
public class SysSubscribeController extends BaseController {
    @Resource
    private SysSubscribeService subscribeService;

    @PostMapping("/subscribe/page")
    @OperationLog(name="根据手机号分页获取预约人数据",type= OperationLogType.PAGE)
    @ApiOperation(value="根据手机号分页获取预约人数据",response = SysSubscribeQueryVo.class)
    public ApiResult<Paging<SysSubscribeQueryVo>> selectSysSubscribeByPhoneNum(@Validated @RequestBody SysSubscribePageParam subscribe)throws Exception{
        Paging<SysSubscribeQueryVo> paging= subscribeService.findSysSubscribeByPhone(subscribe);
        return ApiResult.ok(paging);
    }


    @PostMapping( "/subscribe/add")
    @OperationLog(name = "将商品加入预约表中", type = OperationLogType.ADD)
    @ApiOperation(value ="将商品加入预约表中",response = ApiResult. class)
    public ApiResult<Boolean> addToSubscribe(@Validated(Add.class) @RequestBody SysSubscribe subscribe) throws Exception {
        boolean flag = subscribeService.addToSubscribe(subscribe);
        return ApiResult.result(flag);
    }


    @PostMapping("/subscribe/delete/{id}")
    @OperationLog(name = "删除指定商品", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除指定商品", response = ApiResult.class)
    public ApiResult<Boolean> deleteFromSubscribe(@PathVariable("id")Integer id) throws Exception {
        boolean flag = subscribeService.deleteFromSubscribe(id);
        return ApiResult.result(flag);
    }

    @PostMapping("/subscribe/delete/batch")
    @OperationLog(name = "批量删除", type = OperationLogType.DELETE_BATCH)
    @ApiOperation(value = "批量删除", response = ApiResult.class)
    public ApiResult<Boolean> deleteAllFromSubscribe(@RequestBody List<Integer>ids) throws Exception {
        boolean flag = subscribeService.deleteAllFromSubscribe(ids);
        return ApiResult.result(flag);
    }

    @PostMapping("/subscribe/update")
    @OperationLog(name = "更新预约表中商品", type = OperationLogType.UPDATE)
    @ApiOperation(value = "更新预约表中商品", response = ApiResult.class)
    public ApiResult<Boolean> updateSubscribeById(@Validated(Update.class) @RequestBody SysSubscribe sysSubscribe) throws Exception {
        boolean flag = subscribeService.updateSubscribeById(sysSubscribe);
        return ApiResult.result(flag);
    }

    @GetMapping("/subscribe/detail/info/{id}")
    @OperationLog(name = "根据id获取预约表详细信息", type = OperationLogType.INFO)
    @ApiOperation(value = "根据id获取预约表详细信息", response = ApiResult.class)
    public ApiResult<SysSubscribeQueryVo> getSubscribeById(@PathVariable("id") Integer id) throws Exception {
        SysSubscribeQueryVo sysSubscribeQueryVo = subscribeService.getSubscribe(id);
        return ApiResult.ok(sysSubscribeQueryVo);
    }

}
